package rickyGame.game.action
{
	import ricky.events.AnimEvent;
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.game.graphic.Graphic;
	import ricky.utils.FrameManager;
	
	import rickyGame.game.Fighter;
	import rickyGame.game.GameState;
	import rickyGame.game.action.ActionHelper;
	import rickyGame.game.graphic.FightGraphic;
	import rickyGame.game.property.FightPro;
	
	public class HurtAct extends Act2D
	{
		/**
		 * actor:Actor 受伤对象
		 * deadTime:Number 尸体持续时间
		 * par:Number;伤害值
		 */
		public function HurtAct(actor:Fighter,par:Number)
		{
			super(actor);
			this._animProperty= "beAttack";
			this._state=0;
			_par=par;
			_fighter=actor;
		}
		
		override public function begin():void
		{
			this._state=1;
			if(!_fighter.isDead)//如果没死
			{
				super.begin();
				var g:Graphic=actor.graphic as Graphic;
				if(g.clothes)
				{
					g.clothes.addEventListener(AnimEvent.Anim_Effect,animEffctFun);
					g.clothes.addEventListener(AnimEvent.Anim_End,animEndFun);
				}

			}else
				this.complete();
		}
		
		private function animEffctFun(e:AnimEvent):void
		{
			if(_ishurt==false)
				hurtEffect();
		}
		
		private function hurtEffect():void
		{
			if(actor && actor.isDead==false)
			{
				_ishurt=true;
				Graphic(actor.graphic).clothes.removeEventListener(AnimEvent.Anim_Effect,animEffctFun);
				var fp:FightPro=_fighter.fightPro;//.;
				fp.hp.agileValue=fp.hp.agileValue+_par;
				
				if(_fighter.graphic is FightGraphic)
					FightGraphic(_fighter.graphic).showBloodBar();
				
				if(this._effectNext)
					ActionHelper.inst.addAct(_effectNext);
			}
		}
		
		private function animEndFun(e:*):void
		{
			this._state=3;

			if(_ishurt==false)
				hurtEffect();
			if(actor && actor.graphic)
			{
				Graphic(actor.graphic).clothes.removeEventListener(AnimEvent.Anim_End,animEndFun);

//				if(this.getActor.)
//					actor.playAnimAct(actor.act.animProperty);
//				else
//					actor.playAnimAct("stand");
			}
			
			if(_fighter.fightPro.hp.agileValue<=0 && _fighter.isDead==false)//死亡
			{
				var de:DeathAct=new DeathAct(actor);	
				_fighter.addAct(de);
			}
			this.complete();
		}
		
//		override public function end():void
//		{
//			super.end();
//		}
		
//		override public function dispose():void
//		{
//			super.dispose();
//		}
		
		
		//private ************************************************

		private var _lastanimProperty:String;//
		private var	_par:Number;//受伤值
		private var _fighter:Fighter;//
		private var _ishurt:Boolean=false;//是否计算过伤害 用于动画配置文件错误没有效果贞
	}
}